package com.easy.frame.servers.sys.dataauth;

import com.easy.frame.base.service.mp.dataauth.component.DataAuthCacheHelper;
import com.easy.frame.base.service.mp.dataauth.config.AbstractDataAuthConfig;
import com.easy.frame.servers.sys.entity.SysStaff;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;

/**
 * 数据权限配置类
 *
 * @author zzf
 * @date 2021/2/19 15:55
 */
@Slf4j
@ConditionalOnProperty(prefix = "ef.enabled", value = "dataAuth")
@Configuration
public class MyDataAuthConfig extends AbstractDataAuthConfig {

    protected MyDataAuthConfig() {
        super(new MyDataAuthStrategy());
    }

    /**
     * 初始化数据权限缓存数据
     */
    @Override
    protected void handlerConfigInit() {
        DataAuthCacheHelper helper = new DataAuthCacheHelper()
                .setSqlHandler(new MyRoleDataAuthSqlHandler())
                .addTargetEntityClass(SysStaff.class)
                .setTargetFieldName(SysStaff::getTenantId)
                .bind();
        helper.cache();
    }

}
